using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(LightProbePlacement))]
public class LightProbePlacementEditor : Editor
{
    LightProbePlacement lightProbePlacement;

    void OnEnable() => lightProbePlacement = (LightProbePlacement)target;

    public override void OnInspectorGUI()
    {
        if (target == null)
        {
            return;
        }

        serializedObject.Update();
        
        CreateTempMesh();

        EditorGUILayout.Space();

        LightProbePlacement();
        
        SceneView.RepaintAll();
        serializedObject.ApplyModifiedProperties();
        
    }

    private void CreateTempMesh()
    {
        GUILayout.Label("创建烘培用的Mesh", new GUIStyle(EditorStyles.boldLabel));

        SerializedProperty serializedbakedMeshRoot = serializedObject.FindProperty("BakedMeshRoot");
        EditorGUILayout.PropertyField(serializedbakedMeshRoot);

        if (GUILayout.Button("生成Mesh"))
        {
            lightProbePlacement.BakeBatchMesh();
        }
    }

    private void LightProbePlacement()
    {
        GUILayout.Label("创建Light Probe", new GUIStyle(EditorStyles.boldLabel));
        
        EditorGUILayout.PropertyField(serializedObject.FindProperty("goLightProbeGroup"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("showLightProbeVolume"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("lightProbeVolumeMin"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("lightProbeVolumeMax"));

        EditorGUILayout.PropertyField(serializedObject.FindProperty("density"), new GUIContent("分布密度："));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("radiusMin"), new GUIContent("分布最大半径："));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("radiusMax"), new GUIContent("分布最小半径："));
        
        if (GUILayout.Button("创建Light Probe"))
        {
            lightProbePlacement.Placement();
        }
    }
}
